package com.example.mapper;

import com.example.domain.po.Orders;
import com.example.domain.vo.OrderVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface OrdersMapper {

    List<OrderVo> list(@Param("userId") Integer userId,  @Param("status") Integer status, @Param("startTime") String startTime,@Param("endTime") String endTime);

    Orders findById(Integer id);

    void cancelOrder(Orders order);

    @Select("select * from orders where  order_no=#{orderNo}")
    Orders selectByOrderNo(String orderNo);

    void updateById(Orders orders);

    @Select("select * from orders " +
            "where course_id =#{cId} and user_id = #{uId} and status=2 " +
            "limit 0,1 ")
    Orders getByUidAndCid( @Param("cId") Integer cId,@Param("uId") Integer uId);

    @Insert("insert into orders values " +
            "(null,#{orderNo},#{userId},#{courseId},now(),1,null,null,DATE_ADD(NOW(), INTERVAL 30 MINUTE))")
    void add(Orders orders);

    @Select("select * from orders " +
            "where status=#{i} and cancel_time < NOW() - INTERVAL 30 MINUTE ")
    List<Orders> listExpiredByStatus(int i);

    void cancelOrderList(List<Orders> oList);

    @Select("select * from orders " +
            "where order_no = #{orderNo} ")
    Orders getByOrderNo(Long orderNo);

    @Select("SELECT * FROM orders WHERE TIMESTAMPDIFF(minute, order_date,now() ) >= #{time} and `status` = #{status}   ")
    List<Orders> findUnpaidOrdersOver30Minutes(@Param("time") Integer time, @Param("status") Integer status);

}
